package player;

import java.awt.Color;

import main.Sprite;

public class Gun extends Sprite {

	int endX, endY;
	double radians;
	int xChange, yChange;
	
	public Gun() {
		super();
		
		x = 300;
		y = 750;
		endX = 300;
		endY = 400;
	}
	
	public void setEndX(int newEndX) {
		endX = newEndX;
	}
	
	public void setEndY(int newEndY) {
		endY = newEndY;
	}
	
	public int GCD(int a, int b) {
		if(b==0) return a;
		else 
			return (GCD(b, a%b));
	}
	
	public void draw(){

		g.setColor(Color.BLUE);
		int slopeX = Math.abs(x - endX);
		int slopeY = Math.abs(y - endY);
		int div = GCD(slopeX, slopeY);
		if(div != 0) {
			slopeX = slopeX/div;
			slopeY = slopeY/div;
		}
		radians = Math.toRadians(90);
		if(slopeX != 0){
			radians = Math.atan((double)slopeY/slopeX);
		}
		xChange = (int) (50 * Math.cos(radians));
		yChange = (int) (50 * Math.sin(radians));
		
		if(endX < x) {
			xChange *= -1;
		}
		if (endY < y) {
			yChange *= -1;
		}
		g.drawLine(x, y, x + xChange, y + yChange);
		
		g.setColor(Color.CYAN);
		g.drawLine(0, 675, 600, 675);
	}

	public int getXChange() {
		return xChange;
	}
	
	public int getYChange() {
		return yChange;
	}
	
	public double getRadians() {
		return radians;
	}

	public int getXDirection() {
		if(endX > x) {
			return -1;
		}
		return 1;
	}

	@Override
	public void think() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean doesCollide(Sprite s) {
		// TODO Auto-generated method stub
		return false;
	}
}
